package com.rtos.model.process.queue;

import com.rtos.model.process.Process;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
 * @Author: biubiu0002
 * @Date: 2021-08-30 23:48
 **/
public class ReadyQueue {
    private volatile static ObservableList<Process> readyQueue = FXCollections.observableArrayList();

    public synchronized static ObservableList<Process> getList() {
        return readyQueue;
    }

    public synchronized static void add(Process process) {
//        FXLock.lock.lock();
        readyQueue.add(process);
//        FXLock.lock.unlock();
    }

    public synchronized static int size() {
        int size = readyQueue.size();
        return size;
    }

    public synchronized static Process pop() {
        if(readyQueue.size()>0){
            Process process = readyQueue.get(0);
            readyQueue.remove(0);
            return process;
        }
        return null;
    }


    public synchronized static void remove(Process process) {
        readyQueue.remove(process);
    }

}
